package executer;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Parser {
	public final static SimpleDateFormat DATE_FORMATTER = new SimpleDateFormat("dd.MM.yyyy HH:mm");
    public final static SimpleDateFormat DATE_FORMATTER_WITH_SEC = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
 	
	
	/**
	 * Parses a string (dd.MM.yyyy HH:mm) into a date
	 * @param dateAsString String to convert
	 */
	public static Date parseToDate(String dateAsString) throws ParseException {
	        
			if (dateAsString == "") {
				return null;
			} else {
				return DATE_FORMATTER.parse(dateAsString);
			}
	}
	
	/**
	 * Parses a string (dd.MM.yyyy HH:mm:ss) into a date
	 * @param dateAsString String to convert
	 */
	public static Date parseToDateWithSec(String dateAsString) throws ParseException {
	        
			if (dateAsString == "") {
				return null;

			} else {
				return DATE_FORMATTER_WITH_SEC.parse(dateAsString);
			}
	}
	
	/**
	 * Returns a string formatted as date (dd.MM.yyyy HH:mm)
	 * @param date Date to convert
	 */
	public static String parseToString(Date date) {
		if (date != null ) {
			return DATE_FORMATTER.format(date);
		} else {
			return null;
		}
	}
}
